package com.yuyang.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.yuyang.gulimall.order.config.AlipayTemplate;
import com.yuyang.gulimall.order.service.OrderService;
import com.yuyang.gulimall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author yu yang
 * @date 2023/2/12 -13:49
 */
@Controller
public class PayWebController {
    @Autowired
    OrderService orderService;
    @Autowired
    AlipayTemplate alipayTemplate;
    @ResponseBody
    @GetMapping(value = "/payOrder",produces = "text/html")
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.payOrder(orderSn);
        //会收到支付宝的响应，响应的是一个页面，只要浏览器显示这个页面，就会自动来到支付宝的收银台页面
        String pay = alipayTemplate.pay(payVo);
        return pay;
    }
}
